# coding=utf-8

class StockNumber(object):

    def __init__(self, row_data):
        self.ts_code = row_data['ts_code']
        self.symbol = row_data['symbol']
        self.name = row_data['name']
        self.area = row_data['area']
        self.industry = row_data['industry']
        self.list_date = row_data['list_date']
        self.all_day: [DayInfo] = []

    def __str__(self):
        return f'{self.ts_code} {self.name} {self.area} {self.industry}'


class StockNumberTxt(object):

    def __init__(self, row_data):
        stock_number = str(row_data['代码']).zfill(6)
        self.ts_code = f'{stock_number}.SH' if stock_number.startswith('60') else f'{stock_number}.SZ'
        self.name = row_data['名称']

    def __str__(self):
        return f'{self.ts_code} {self.name}'


class SHDayInfo(object):

    def __init__(self, df_row_data):
        # 日期,开盘,收盘,最高,最低,成交量,成交额,振幅,涨跌幅,涨跌额,换手率
        self.trade_date = str(df_row_data['日期']).replace('-', '')
        self.open = df_row_data['开盘']
        self.high = round(float(df_row_data['最高']), 2)
        self.low = round(float(df_row_data['最低']), 2)
        self.close = round(float(df_row_data['收盘']), 2)
        self.change = df_row_data['涨跌额']
        self.pct_chg = round(float(df_row_data['涨跌幅']), 2)
        self.vol = df_row_data['成交量']
        self.amount = df_row_data['成交额']

    def __repr__(self):
        return f'{self.trade_date}，' \
               f'最高价{self.high}，' \
               f'最低价{self.low}，' \
               f'涨跌幅：{self.pct_chg}\n'

    def __str__(self):
        return f'{self.trade_date}，' \
               f'最高价{self.high}，' \
               f'最低价{self.low}，' \
               f'涨跌幅：{self.pct_chg}，'


class DayInfo(object):

    def __init__(self, sn, df_row_data):
        self.name = sn.name
        self.ts_code = sn.ts_code
        self.industry = sn.industry
        self.trade_date = df_row_data['trade_date']
        self.trade_date_str = str(df_row_data['trade_date'])
        self.open = round(float(df_row_data['open']), 2)
        self.high = round(float(df_row_data['high']), 2)
        self.low = round(float(df_row_data['low']), 2)
        self.close = round(float(df_row_data['close']), 2)
        self.pre_close = df_row_data['pre_close']
        self.change = df_row_data['change']
        self.pct_chg = round(float(df_row_data['pct_chg']), 2)
        self.vol = df_row_data['vol']
        self.amount = df_row_data['amount']

    def __repr__(self):
        return f'{self.trade_date}，' \
               f'{self.ts_code}，' \
               f'{self.name}，' \
               f'最高价{self.high}，' \
               f'最低价{self.low}，' \
               f'涨跌幅：{self.pct_chg}，' \
               f'开盘价：{self.open}，' \
               f'收盘价：{self.close} \n'

    def __str__(self):
        return f'{self.name},' \
               f'{self.ts_code},' \
               f'高：{self.high},' \
               f'低：{self.low},' \
               f'涨：{self.pct_chg},' \
               f'开：{self.open},' \
               f'收：{self.close}'
        # return f'{self.name},' \
        #        f'{self.ts_code},' \
        #        f'最高价{self.high},' \
        #        f'最低价{self.low},' \
        #        f'涨跌幅：{self.pct_chg},' \
        #        f'开盘价：{self.open},' \
        #        f'收盘价：{self.close}'
        # f'最高价：{self.high}，' \
        # f'最低价：{self.low}，' \
        # f'昨收价：{self.pre_close}，' \
        # f'涨跌额：{self.change}，' \
        # f'成交量 （手）：{self.vol}，' \
        # f'成交额 （千元）：{self.amount}'


class StockNumber2(object):

    def __init__(self, df_row):
        self.ts_code = df_row['ts_code']
        self.symbol = df_row['symbol']
        self.name = df_row['name']
        self.area = df_row['area']
        self.industry = df_row['industry']
        link_code_arr = self.ts_code.split('.')
        link_code = f'{link_code_arr[1]}{link_code_arr[0]}'
        self.link = f'https://xueqiu.com/S/{link_code}'

    def __str__(self):
        return f'{self.ts_code} ' \
               f'{self.name} ' \
               f'{self.area} ' \
               f'{self.symbol} ' \
               f'{self.industry} ' \
               f'{self.link}'


class DayInfo2(object):

    def __init__(self, link, name, industry, df_row):
        self.name = name
        self.industry = industry
        self.ts_code = df_row['ts_code']
        self.trade_date = df_row['trade_date']
        self.open = float(df_row['open'])
        self.high = float(df_row['high'])
        self.low = float(df_row['low'])
        self.close = float(df_row['close'])
        self.pre_close = float(df_row['pre_close'])
        self.change = float(df_row['change'])
        self.pct_chg = float(df_row['pct_chg'])
        self.vol = float(df_row['vol'])
        self.amount = float(df_row['amount'])
        self.link = link

    def __str__(self):
        return f'{self.trade_date}，' \
               f'{self.link}，' \
               f'{self.name}，' \
               f'{self.industry}，' \
               f'{self.ts_code}，' \
               f'开盘价：{self.open}，' \
               f'收盘价：{self.close}，' \
               f'最高价：{self.high}，' \
               f'最低价：{self.low}，' \
               f'昨收价：{self.pre_close}，' \
               f'涨跌额：{self.change}，' \
               f'涨跌幅：{self.pct_chg}，' \
               f'成交量 （手）：{self.vol}，' \
               f'成交额 （千元）：{self.amount}'
